package com.example.wan_android.http

import android.content.Context
import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.HttpUrl


class InMemoryCookieJar() : CookieJar {
    private var cookies: MutableList<Cookie> = ArrayList()

    override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
        this.cookies.addAll(cookies)
    }

    override fun loadForRequest(url: HttpUrl): List<Cookie> {
        val result: MutableList<Cookie> = ArrayList()
        for (cookie in cookies) {
            if (cookie.matches(url)) {
                result.add(cookie)
            }
        }
        return result
    }

    fun clear() {
        cookies = ArrayList()
    }
}